from django.conf import settings

from libs.celery_tasks.main import app
from apps.goods.views import DetailView


@app.task(bind=True, name='gen_detail_html')
def gen_detail_html(self, sku_id):
    response = DetailView().get(None, sku_id)
    file_name = f"{settings.STATICFILES_DIRS[0]}/detail/{sku_id}.html"
    print(file_name)
    with open(file_name, 'w', encoding='UTF-8') as f:
        f.write(response.content.decode())
